<!-- 利润结算-业绩相关 -->
<template>
    <div>
        <el-form :inline="true" :model="ruleForm" class="demo-form-inline">
            <el-form-item label="报表名称：">
                <el-input placeholder="请输入报表名称" v-model.trim="ruleForm.reportName" maxlength="20" size="small"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="success"  @click="searchList" id="monitorEnter" size="small">查询</el-button>
                <el-button type="primary"  @click="generateReport" size="small">生成报表</el-button>
            </el-form-item>
        </el-form>

        <el-table :data="tableData" border style="width: 100%">
            <el-table-column type="index" label="序号" width="50" align="center"></el-table-column>
            <el-table-column label="报表名称" prop="reportName" align="center"></el-table-column>
            <el-table-column label="年份" prop="timeYear" align="center"></el-table-column>
            <el-table-column label="数据来源"  prop="dataSource" align="center">
                <template slot-scope="scope">
                   {{scope.row.dataSource | initdataSource}}
                </template>
            </el-table-column>
            <el-table-column label="利润总额" prop="profitAmount" align="center">
                <template slot-scope="scope">
                    {{scope.row.profitAmount | initCash}}
                </template>
            </el-table-column>
            <el-table-column label="计提方式" prop="drawType" align="center">
                <template slot-scope="scope">
                   {{scope.row.drawType==1? '阶段计提':'通提'}}
                </template>
            </el-table-column>
            <el-table-column label="利润结算金额" align="center">
                 <template slot-scope="scope">
                    <el-button type="text" @click="detailshander(scope.row)">{{scope.row.settleAmount | initCash}}</el-button>
                 </template>
            </el-table-column>
        </el-table>

        <div class="pagebar">
          <el-pagination
            background
            layout="total, sizes, prev, pager, next"
            :current-page.sync="ruleForm.pageNum"
            :page-sizes="[10, 20, 30, 40]"
            :page-size="ruleForm.pageSize"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
            :total="totalSize">
          </el-pagination>
        </div>
        
        <el-dialog
        title=""
        :visible.sync="centerDialogVisible"
        width="50%"
        center>
            <div style="max-height: 500px;overflow-y: auto">
                <!-- 通提的方式  v-if-->
                <div v-show="drawType==2">
                    <el-table :data="infodata" border style="width: 100%">
                       <el-table-column label="利润总额" prop="profitAmount" align="center">
                           <template slot-scope="scope">
                               {{scope.row.profitAmount | initCash}}
                           </template>
                       </el-table-column>
                       <el-table-column label="计提点数%" prop="extractProportion" align="center"></el-table-column>
                       <el-table-column label="利润结算金额" prop="settleAmount" align="center">
                         <template slot-scope="scope">
                             {{scope.row.settleAmount | initCash}}
                         </template>
                       </el-table-column>
                    </el-table>
                </div>
                <!-- 阶段计提方式 -->
                <div v-show="drawType==1">
                    <el-table :data="infodata" border style="width: 100%">
                       <el-table-column label="利润区间（万元)" prop="range" align="center"></el-table-column>
                       <el-table-column label="利润区间总额" prop="profitAmount" align="center">
                           <template slot-scope="scope">
                               {{scope.row.profitAmount | initCash}}
                           </template>
                       </el-table-column>
                       <el-table-column label="计提点数%" prop="extractProportion" align="center"></el-table-column>
                       <el-table-column label="利润结算金额" prop="settleAmount" align="center">
                           <template slot-scope="scope">
                               {{scope.row.settleAmount | initCash}}
                           </template>
                       </el-table-column>
                    </el-table>
                </div>
            </div>
            <span slot="footer" class="dialog-footer">
                <el-button type="primary" @click="centerDialogVisible = false">关闭</el-button>
            </span>
        </el-dialog>
    </div>
</template>
<script>
    import api from '@/api/apiPath'
    export default {
        name:'profitSettlementPerformance',
        title:'利润结算',
        data () {
            return {
                ruleForm:{
                    reportName:undefined,
                    pageNum: 0,
                    pageSize: 10,
                },
                totalSize:0,
                drawType:undefined,//计提方式 1 阶段 2通提
                centerDialogVisible:false,
                tableData:[],
                infodata:[]
            }
        },
        filters:{
            initCash(cellValue){
                if(cellValue !== 0 ){
                    return cellValue.toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");
                }
                if(cellValue == 0){
                    return "0.00"
                }
            },
            initdataSource(val){
                if (val == 1) {
                    return '项目等级'
                }else if (val == 2) {
                    return '开发商类型'
                }else if(val == 3){
                    return '营收利润'
                }
            }
        },
        methods:{
            handleCurrentChange(){
                this.getlist()
            },
            handleSizeChange(val){
                this.ruleForm.pageSize = val
                this.getlist();
            },
            getlist(){
                this.axios.post(api.PROSETTLEREPORT,this.ruleForm).then((res) => {
                  if (res && res.data.code == 200) {
                        this.tableData = res.data.data.list
                        this.totalSize = res.data.data.total
                   }
                }) 
            },
            generateReport(){
                this.$router.push({path:'/profitSettlementReport'})
            },
            searchList(){
                this.ruleForm.pageNum = 1
                this.getlist();
            },
            detailshander(row){
                this.centerDialogVisible = true
                this.drawType = row.drawType
                this.axios.post(api.PROFIEDETAIL,{id:row.id}).then((res) => {
                  if (res && res.data.code == 200) {
                        this.infodata = res.data.data
                   }
                }) 
            }
        },
        activated(){
          this.searchList()
        },
        created(){
            this.getlist()
        }
    }
    
</script>

<style lang="stylus" scoped>
</style>
